package com.itheima.work;

import com.itheima.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

// work模式的生产者
public class Producer {
    static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {
        // 创建连接
        Connection connection = ConnectionUtil.getConnection();
        // 创建消息通道
        Channel channel = connection.createChannel();
        // 创建队列
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);
        // 定义要发送的信息
        for (int i = 1; i <=5 ; i++) {
            String message = "你好呀...我是可爱的小兔纸..."+i;
            // 由通道的队列进行发送
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            System.out.println("已经发送的消息:"+message);
        }
        channel.close();
        connection.close();
    }
}
